from typing import List

import pandas as pd

from basic.entiys.charts.BaseCharts import BaseCharts, BaseChartsDTO

filename = "./datas/Chars.xlsx"

myChartTable = pd.read_excel(filename)


class ChartListGenerate:
    """
    利用表格的信息生成多个角色
    """

    @classmethod
    def getCharacters_power(cls, power) -> List[BaseCharts]:
        """
        通过阵营名称获取角色
        :param power:
        :return:
        """
        group_ret = myChartTable.groupby("阵营")
        my_power_df = ...
        for gn, gdf in group_ret:
            if gn == power:
                my_power_df = gdf
                break
        chart_names = my_power_df['姓名'].tolist()
        chart_instances = [ChartGenerate.getCharacter_name(i) for i in chart_names]
        return chart_instances

    @classmethod
    def getCharacters_name(cls, name) -> List[BaseCharts]:
        """
        根据角色名称获取同阵营的角色(包括自己)
        :param name:
        :return:
        """
        charts = ChartGenerate.getCharacter_name(name)
        powername = charts.fields.power
        return cls.getCharacters_power(powername)


class ChartGenerate:
    """
     利用表格的信息生成一个角色
    """

    @classmethod
    def getCharacter_name(cls, name) -> BaseCharts:
        """
        通过名称获取用户
        :param name:
        :return:
        """
        info: pd.DataFrame = myChartTable[myChartTable['姓名'] == name]
        dto = BaseChartsDTO(*info.iloc[0].tolist())
        chart = BaseCharts(dto)
        return chart
